﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MedicalSystems
{
    class ClassificationTable
    {
        public ClassificationTable()
        {
        }

        public Intersection intersecs(Record one, Record two)
        {
            if ((one.startTime >= two.startTime && one.startTime <= two.finishTime) ||
                (two.startTime >= one.startTime && two.startTime <= one.finishTime))
                return new Intersection(Max(one.startTime, two.startTime), Min(one.finishTime, two.finishTime));
            return null;
        }

        private DateTime Min(DateTime one, DateTime two)
        {
            if (one < two) return one;
            return two;
        }

        private DateTime Max(DateTime one, DateTime two)
        {
            if (one > two) return one;
            return two;
        }

        public string getHemoglobinState(Record r)
        {
            double hem = Convert.ToDouble(r.ParamValue);
            if (r.Gender == "F")
            {
                if (hem >= 0 && hem < 8) return "Sever Anemia";
                if (hem >= 8 && hem < 10) return "Moderate Anemia";
                if (hem >= 10 && hem < 12) return "Mild Anemia";
                if (hem >= 12 && hem < 14) return "Normal Hemoglobin";
                return "Polycytemia";
            }
            else
            {
                if (hem >= 0 && hem < 9) return "Sever Anemia";
                if (hem >= 9 && hem < 11) return "Moderate Anemia";
                if (hem >= 11 && hem < 13) return "Mild Anemia";
                if (hem >= 13 && hem < 16) return "Normal Hemoglobin";
                return "Polycytemia";
            }
        }

        internal string getHematologicalState(Record r, Record w)
        {
            double hem = Convert.ToDouble(r.ParamValue);
            double wbc = Convert.ToDouble(w.ParamValue);
            if (r.Gender == "M")
            {
                if (hem >= 0 && hem < 13)
                {
                    if (wbc < 4000) return "Pancytopenia";
                    if(wbc > 10000) return "Suspected Leukemia";
                    return "Anemia";
                }
                if (hem >= 13 && hem < 16)
                {
                    if (wbc < 4000) return "Leukopenia";
                    if (wbc > 10000) return "Leukemoid reaction";
                    return "Normal";
                }
                if (wbc < 4000) return "Suspected Polycytemia Vera";
                if (wbc > 10000) return "Suspected Polycytemia Vera";
                return "Polyhemia";
            }
            else
            {
                if (hem >= 0 && hem < 12)
                {
                    if (wbc < 4000) return "Pancytopenia";
                    if (wbc > 10000) return "Suspected Leukemia";
                    return "Anemia";
                }
                if (hem >= 12 && hem < 14)
                {
                    if (wbc < 4000) return "Leukopenia";
                    if (wbc > 10000) return "Leukemoid reaction";
                    return "Normal";
                }
                if (wbc < 4000) return "Suspected Polycytemia Vera";
                if (wbc > 10000) return "Suspected Polycytemia Vera";
                return "Polyhemia";
            }
        }
    }
}
